package applogic

import (
	"encoding/json"

	"auto/model"
	"github.com/gin-gonic/gin"
)

func Parse(c *gin.Context) {
	var palyerurl []map[string]any
	data, _ := c.GetRawData()
	err := json.Unmarshal(data, &palyerurl)
	if err != nil {
		c.JSON(200, gin.H{"err": err, "playerlist": nil})
		return
	}

	for _, m := range palyerurl {
		var player model.PlayerList
		var db = model.Md.DB.Where("播放页面 = ?", m["playerUrl"]).First(&player)
		if err := db.Error; err == nil {
			player.M3U8Url = channel.ParseM3U8(m["playerUrl"].(string)).(string)
			db.Save(player)
		}
	}

	c.JSON(200, gin.H{"err": err, "parseOut": palyerurl})
}
